package com.mostromas.ess.product.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mostromas.ess.entities.Composition;
import com.mostromas.ess.entities.Supplier;
import com.mostromas.ess.product.mapper.CompositionMapper;
import com.mostromas.ess.product.req.CompositionREQ;
import com.mostromas.ess.product.service.ICompositionService;
import com.mostromas.ess.util.base.Result;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CompositionServiceImpl extends ServiceImpl<CompositionMapper, Composition> implements ICompositionService {
    @Override
    public Result queryList(CompositionREQ req) {
        QueryWrapper<Composition> wrapper = new QueryWrapper<>();

        if(StringUtils.isNotEmpty(req.getName())){
            wrapper.like("name",req.getName());
        }
        if(StringUtils.isNotEmpty(req.getEnglish())){
            wrapper.like("english",req.getEnglish());
        }
        wrapper.orderByAsc("sort");
        List<Composition> data = baseMapper.selectList(wrapper);
        return Result.ok(data);
    }
}
